package com.zenith.edu.controller;

import com.zenith.common.annotation.request.SecurePostMapping;
import com.zenith.common.result.Result;
import com.zenith.edu.po.dto.EduLiveSessionDTO;
import com.zenith.edu.po.vo.EduLiveSessionVO;
import com.zenith.edu.service.EduLiveSessionService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/edu/live-session")
@Tag(name = "直播课堂管理", description = "直播课堂管理接口")
public class EduLiveSessionController {
    
    @Autowired
    private EduLiveSessionService eduLiveSessionService;
    
    @SecurePostMapping(value = "/createLiveSession", roles = "ROLE_ADMIN", permission = "live-session:create")
    @Operation(summary = "创建直播课堂")
    public Result<EduLiveSessionVO> createLiveSession(@RequestBody EduLiveSessionDTO dto) {
        EduLiveSessionVO liveSessionVO = eduLiveSessionService.createLiveSession(dto);
        return Result.success(liveSessionVO);
    }
    
    @SecurePostMapping(value = "/getLiveSessionById/{id}", roles = "ROLE_ADMIN", permission = "live-session:read")
    @Operation(summary = "根据ID获取直播课堂详情")
    public Result<EduLiveSessionVO> getLiveSessionById(@PathVariable Long id) {
        EduLiveSessionVO liveSessionVO = eduLiveSessionService.getLiveSessionById(id);
        if (liveSessionVO == null) {
            return Result.fail("直播课堂不存在");
        }
        return Result.success(liveSessionVO);
    }
    
    @SecurePostMapping(value = "/updateLiveSession", roles = "ROLE_ADMIN", permission = "live-session:update")
    @Operation(summary = "更新直播课堂信息")
    public Result<EduLiveSessionVO> updateLiveSession(@RequestBody EduLiveSessionDTO dto) {
        EduLiveSessionVO liveSessionVO = eduLiveSessionService.updateLiveSession(dto);
        return Result.success(liveSessionVO);
    }
    
    @SecurePostMapping(value = "/deleteLiveSession/{id}", roles = "ROLE_ADMIN", permission = "live-session:delete")
    @Operation(summary = "删除指定直播课堂")
    public Result<Void> deleteLiveSession(@PathVariable Long id) {
        boolean result = eduLiveSessionService.deleteLiveSession(id);
        if (!result) {
            return Result.fail("直播课堂删除失败");
        }
        return Result.success();
    }
    
    @SecurePostMapping(value = "/getLiveSessionList", roles = "ROLE_ADMIN", permission = "live-session:read")
    @Operation(summary = "获取直播课堂列表")
    public Result<List<EduLiveSessionVO>> getLiveSessionList() {
        List<EduLiveSessionVO> liveSessionList = eduLiveSessionService.getLiveSessionList();
        return Result.success(liveSessionList);
    }
}